﻿using System;
using Ext.Net;
using System.Xml.Xsl;
using System.Xml;
using BLL;
using Model;
using System.Collections.Generic;
using System.Web.UI.WebControls;

namespace Web.View.publishNews
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
        //绑定Grid
        protected void News_InfoBind(object sender, StoreRefreshDataEventArgs e)
        {
            newsinfoMgr mgr = new newsinfoMgr();
            e.Total = int.Parse(mgr.GetRecordCount_newsinfo(e.Parameters[this.News_Filter.ParamPrefix]));
            IList<newsInfo> list = mgr.FindAllByPage_newsinfo(e.Start.ToString(), e.Limit.ToString(), e.Parameters[this.News_Filter.ParamPrefix]);
            News_MainStore.DataSource = list;
            News_MainStore.DataBind();
        }
        protected void BtnAdd_Click(object sender, DirectEventArgs e)
        {
            News_Win.Html = "<iframe id='editorframe' width='610' height='360' frameborder='0' scrolling='no' src='Editor.aspx' />";
            News_Win.Show();
        }
        //双击表格
        protected void News_GridDBClick(object sender, DirectEventArgs e)
        {
            News_Win.Html = "<iframe id='editorframe' width='610' height='360' frameborder='0' scrolling='no' src='Editor.aspx?id="+e.ExtraParams["id"].ToString()+"' />";
            News_Win.Show();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            newsinfoMgr mgr = new newsinfoMgr();
            RowSelectionModel sm = this.News_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                newsInfo _newsinfo = new newsInfo();
                _newsinfo.newsid = int.Parse(row.RecordID);
                if (mgr.Del_newsinfo(_newsinfo))
                    X.Msg.Notify("成功", "<font color='green' size='3'>已经成功删除选中的记录</font>").Show();
                else
                    X.Msg.Notify("失败", "<font color='green' size='3'>删除记录失败，请您重试！</font>").Show();
            }
            News_Grid.Reload();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();
        }
    }
}